<!DOCTYPE html>
<#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
<#assign fillDept=JspTaglibs["http://www.casic304.cn/fillDept"] />
<html>
<head>
    <meta charset="utf-8">
    <title>质量奖惩信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <!--<link rel="stylesheet" href="/qbdmsStatic/style/forms/currencyCss.css">-->
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBody">

<div class="qbdms-bodyDiv">
    <div class="layui-table-view-body qbdms-add-view-body">
        <form class="layui-form formPreview" requrl="${ctx}/qbdms/wQbdQualityRewardsMessage/get" lay-filter="wQbdQualityRewardsMessageDataForm">

            <div class="qbdms-formTitle" style="border-bottom: 1px solid #E5F0FF">质量奖惩信息 <i  class="qbdms-returnOn closeWindow">返回</i></div>
            <div class="qbdms-formBody">
                <div class="dragInfo temSpace" id="tbxx"></div>
                <div class="layui-row">
                    <div class="" style="display: none;">
                        <label class="layui-form-label qbdms-label" title="主键">主键</label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="id"  placeholder="请输入" fieldname="id"
                                   autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>

                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="单位名称">单位名称<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="companyName"  placeholder="请输入"
                                   autocomplete="off" class="layui-input" maxlength="50" fieldname="companyName" disabled/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="事件名称">事件名称<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="incidentName"  placeholder="请输入" lay-verify="required" lay-reqtext="事件名称是必填项"
                                   autocomplete="off" class="layui-input" maxlength="50" fieldname="incidentName">
                        </div>
                    </div>
                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="密级">密级<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@secSelect.sec_select required=true data_src=1 name="secret"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="类别">类别<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <select name="qualityType" lay-filter="qualityType" lay-verify="required" lay-reqtext="类别是必填项">
                                <option></option>
                            </select>
                        </div>
                    </div>
                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="是否完成责任追究">是否完成责任追究<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <select name="completeAccountabilityFlag" lay-filter="qualityType">
                                <option></option>
                            </select>
                        </div>
                    </div>
                    <div class="qbdms-oneForm  ">
                        <label class="layui-form-label qbdms-label" title="总金额">总金额</label>
                        <div class="layui-input-block qbdms-input qbdms-money">
                            <input type="text" name="aggregateAmount"
                                   autocomplete="off" class="layui-input" maxlength="50" fieldname="aggregateAmount" disabled/>
                        </div>
                    </div>
                    <div class="qbdms-textarea  ">
                        <label class="layui-form-label qbdms-label" title="奖惩原因">奖惩原因</label>
                        <div class="layui-input-block qbdms-input">
                            <textarea rows="2" name="rewardsReason"  placeholder="请输入"
                                      autocomplete="off" class="layui-textarea"
                                      maxlength="500" fieldname="rewardsReason"></textarea>
                        </div>
                    </div>
                    <div class="qbdms-textarea  ">
                        <label class="layui-form-label qbdms-label" title="认定情况">认定情况<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <textarea rows="2" name="firmlyBelieveSituation"  placeholder="请输入" lay-verify="required"
                                      autocomplete="off" class="layui-textarea" lay-reqtext="认定情况是必填项"
                                      maxlength="500" fieldname="firmlyBelieveSituation"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <p class="qbdms-SubTableTitle"><span>质量奖惩详细信息</span></p>
            <div class="qbdms-tableDiv">
                <a modetype="2" class="addFormTr1"
                   id="add"><i class="layui-icon layui-icon-addition"></i>新增</a>
                <table class="qbdms-temTable wQbdQualityRewardsMsgSubList subFormTable"
                       id="wQbdQualityRewardsMsgSubList" style="min-width: 1560px;">
                    <tbody>
                    <tr class="temSpace qbdms-temTable-thead">
                        <td class="temSpace" style="width: 30px;">
                            序号
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            单位名称<span style="color: red;">*</span>
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            奖励/处罚总人数<span style="color: red;">*</span>
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            是否行政处分
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            其中行政处分人数
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            金额(元)
                        </td>
                        <td class="temSpace subDialogShowState" style="width: 120px">
                            详细信息
                        </td>
                        <td class="temSpace qbdms-subOptState">
                            管理
                        </td>
                    </tr>
                    <tr class="temSpace subContTem">
                        <td class="temSpace qbdms-temTable-seNumber">
                            <div class="temTag">0</div>
                        </td>
                        <td class="temSpace qbdms-temTable-td">
                            <input type="text" placeholder="请输入" requiredFlag="required"
                                   autocomplete="off" class="layui-input" maxlength="100"
                                   name="s:wQbdQualityRewardsMsgSubList:companyName" lay-reqtext="单位名称是必填项"/>
                        </td>
                        <td class="temSpace qbdms-temTable-td">
                            <input type="text" placeholder="请输入" requiredFlag="required|num"
                                   autocomplete="off" class="layui-input" maxlength="100"
                                   name="s:wQbdQualityRewardsMsgSubList:headcount" lay-reqtext="处罚/奖励总人数是必填项"/>
                        </td>
                        <td class="temSpace qbdms-temTable-td">
                            <select name="s:wQbdQualityRewardsMsgSubList:disciplinarySanctionFlag">
                                <option></option>
                            </select>
                        </td>
                        <td class="temSpace qbdms-temTable-td">
                            <input type="text" placeholder="请输入" requiredFlag="num"
                                   autocomplete="off" class="layui-input" maxlength="9"
                                   name="s:wQbdQualityRewardsMsgSubList:disciplinarySanctionCount"/>
                        </td>
                        <td class="temSpace qbdms-temTable-td qbdms-money">
                            <input type="text" placeholder="请输入" requiredFlag="money"
                                   autocomplete="off" class="layui-input" maxlength="10"
                                   name="s:wQbdQualityRewardsMsgSubList:money" lay-filter="s:wQbdQualityRewardsMsgSubList:money"/>
                        </td>
                        <td class="temSpace qbdms-temTable-td">
                            <input type="text" placeholder="请输入"
                                   autocomplete="off" class="layui-input" maxlength="100"
                                   name="s:wQbdQualityRewardsMsgSubList:detailedInfomation" lay-filter="s:wQbdQualityRewardsMsgSubList:detailedInfomation"/>
                        </td>
                        <td class="temSpace qbdms-subOptState">
                            <a class="subDeleteTr RightBtn">删除</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>


            <div class="layui-form-item btnformItem">
                <p>
                    <span id="hideAndShow" style="display: none;">
                        <a lay-submit lay-filter="wQbdQualityRewardsMessage" class="layui-btn btn-n privateSubmit qbdms-oneBtn"
                           requrl="${ctx}/qbdms/wQbdQualityRewardsMessage/save">提交</a>
                    </span>
                    <button type="reset" id="closeWindow" style="margin-left: 10px;"
                            class="layui-btn layui-btn-sm btn-save qbdms-oneBtnLine">取消
                    </button>
                </p>
            </div>
        </form>
    </div>
</div>

<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>

    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','setter','upload','propsHandle', 'common','jquery','laydate','layer','publicMethods','qbdmsForm'], function () {

        // -----常量声明----------
        var $ = layui.jquery,
            laydate = layui.laydate,
            setter = layui.setter,  // 配置信息
            layer = layui.layer,
            upload = layui.upload,
            publicMethods = layui.publicMethods,
            propsHandle = layui.propsHandle,
            form = layui.qbdmsForm;
        //- 添加表单验证规则 开始 ---------------------------------------------------------------------
        form.verify({
//            integer: [/^[+]{0,1}(\d+)$/,'请输入正整数'],
//            money: [/^((0{1}\.\d{1,2})|([1-9]\d*\.{1}\d{1,2})|([1-9]+\d*))$/,'请输入正整数和两位小数的数据'],
            length100:[/^.{0,100}$/,'输入字符数不能超过100'],
            length2000:[/^.{0,2000}$/,'输入字符数不能超过2000'],
            fileRequired:[/[\S]+/,"没有上传对应附件"],
            num: function (value) {
                // 如果值为空，不触发校验
                if (value && !new RegExp(/^[1-9]\d*$/).test(value)) return "只能输入非负整数";

            },
            money: function (value) {
                if (value && !new RegExp(/^((0{1}\.\d{1,2})|([1-9]\d*\.{1}\d{1,2})|([1-9]+\d*))$/).test(value)) {
                    return '请输入数字且小数最多两位';
                }
            },
        });

        var defProps = {
            //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
            viewMould: 'moulds/', // 组件模块 存放文件 *****
            formAreaInfo: 'html',
            temDate: '.temDate',
            uploadFileBtn: '.uploadFileBtn',
            uploadImgBtn: '.uploadImgBtn',
            richTextArea: '.richTextArea',
            selectInput: '.selectInput',
            radioOptionCont: '.radioOptionCont',
            dataLexiTree: '.dataLexiTree',
            selectorBtn: '.selectorBtn',
        },
            temQuery = new propsHandle() ;

        // 初始化模板功能
        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });

        // 子表初始化事件
        temQuery.initSubEvent(defProps, serverPath, setter);

        //- 添加表单验证规则 结束 ---------------------------------------------------------------------

//        $("[lay-verify='required']").attr("lay-verify", "");
        var dateTimeFiledLen = $(".dateTimeFiled");
        for(var i=0;i<dateTimeFiledLen.length;i++){
            laydate.render({
                elem: dateTimeFiledLen[i] //指定元素
                ,type: 'year'
                ,trigger: 'click'
            });
        }

        /**-------数据字典初始化-------**/
        $().ready(function () {
            //类别
            var lbList = eval('${lbList}');
            var lbHtml = "";
            $.each(lbList, function (index, obj) {
                lbHtml += "  <option value='" + obj.itemValue + "'>" + obj.itemName + "</option>";
            });
            $("select[name='qualityType']").append(lbHtml);
            //是否行政处分
            var sfList = eval('${sfList}');
            var sfHtml = "";
            $.each(sfList, function (index, obj) {
                sfHtml += "  <option value='" + obj.itemValue + "'>" + obj.itemName + "</option>";
            });
            $("select[name='completeAccountabilityFlag']").append(sfHtml);
            $("select[name='s:wQbdQualityRewardsMsgSubList:disciplinarySanctionFlag']").append(sfHtml);

        });

        laydate.render({
            elem: '.temDate'
        });

        //关闭当前页面
        $("#closeWindow,.closeWindow").click(function () {
            window.location.href = '${ctx}/qbdms/wQbdQualityRewardsMessage/view/list';
        });

        form.on("select(qualityType)",function (data) {
            if(data.value === "责任追究"){
                $("select[name='completeAccountabilityFlag']").attr("lay-verify","required");
                $("select[name='completeAccountabilityFlag']").attr("lay-reqtext","是否完成责任追究是必填项");
            }else{
                $("select[name='completeAccountabilityFlag']").removeAttr("lay-verify");
                $("select[name='completeAccountabilityFlag']").removeAttr("lay-reqtext");
            }
        })

        var runId = "${runId}";
        if(runId == null || runId == ''){
            $("#hideAndShow").show();
        }

        $(".subContTem").hide();

        var count = 1;
        $(document).on('click', '.addFormTr1', function () {
            count += 1;
            var modetype = $(this).attr('modetype'),
                copyObj = $(this).parent().children('.subFormTable'),
                copyHtm = copyObj.find('tr').eq(1);
            if (modetype === '2') {
                //在这里做一个转换，控制子表隐藏行的必填
                var copyHtmlStr = copyHtm.html();
                copyHtmlStr = copyHtmlStr.replace(/requiredflag/g, "lay-verify");
                // 表格
                copyObj.append('<tr class="temSpace">' + copyHtmlStr + '</tr>');
                var trArr = copyObj.find('tr');
                trArr.eq(trArr.length - 1).find('td').eq(0).find('.temTag').html(trArr.length - 2);

                trArr.eq(trArr.length - 1).find('[isinit="1"]').each(function (i, item) {
                    $(item).attr('isinit', '2');
                });
                if (trArr.length > 3) {
                    trArr.eq(trArr.length - 1).find('[type=radio]').each(function (i, item) {
                        $(item).attr('name', (trArr.eq(1).find('[type=radio]').eq(i).attr('name')) + '_' + (trArr.length - 2))
                    });
                }
                temQuery.initTemEvent(defProps, serverPath, setter);
            } else if (modetype === '1') {
                // updateTr(copyObj, copyHtm);
            }
            form.render();
            lay('.datetime').each(function () {
                laydate.render({
                    elem: this
                    , type: 'year'
                    , trigger: 'click'
                });
            });
            $(".datetime").removeAttr("lay-key");
            publicMethods.bottomFixd()
        });

        var filldept = "${filldept}";
        $("input[name='companyName']").val(filldept);

        var id = "${id}";
        if (id == null || id === '') {
            $("#tbxx").html("<span class='qbdms-TBinformation'>填报信息:</span><span class='qbdms-TBinformationText'>【${filldept}   | ${fillman}  | ${filldate}】</span>");
        }

        var common = layui.common;
        common.updateForm({
            name:'wQbdQualityRewardsMessageDataForm',
            idValue:"${id}",
            primary:"id",
            getCallback:function (data) {
                var returnData = data.data;

//                $("[name='secret']").attr("disabled",true);//设置密级下拉框在修改时不可编辑

                $("#tbxx").html("<span class='qbdms-TBinformation'>填报信息:</span>" +
                    "<span class='qbdms-TBinformationText'>【"+returnData.filldept+"   | "+returnData.fillman+"  | "+returnData.filldate+"】</span>");

                //-修改页面 初始化子表 开始 ------------------------------------------

                $('table.subFormTable').each(function () {
                    console.log($(this).attr('class').split(" ")[1]);

                    var table = {
                        tableName: $(this).attr('class').split(" ")[1],
                        fields: []
                    };
                    table.fields = returnData[table.tableName];
                    if(table.fields.length > 0){
                        for (var i = 0, len = table.fields.length; i < len; i++) {
                            var dataRow = table.fields[i];
                            var temp = $("." + table.tableName).prev().click();
                            //这里有子表表头占一行，子表隐藏行占一行，所以取需要赋值的行时，需要temp=i+2
                            var domRow = $(this).find("tr.temSpace:eq(" + (i * 1 + 2) + ")");
                            $.each(dataRow, function (j, val) {
                                var domItem = domRow.find("[name$='" + j + "']");
                                if (domItem) {
                                    domItem.val(val);
                                }
                            });
                        }
                    }
                });

            },
            beforeSubmitFun:function (data) {
                //子表数据
                var sub = [];
                $('table.subFormTable').each(function () {
                    var table = {
                        tableName: $(this).attr('class').split(" ")[1],
                        fields: []
                    };
                    $(this).find('tr.temSpace').each(function (i, item) {    /*修复需要提交隐藏的行数据的bug*/
                        if (i > 1) {
                            var row = {};
                            var objRow = $(this);
                            $("input:text[name^='s:'],input[type='hidden'][name^='s:'],textarea[name^='s:'],select[name^='s:'],ul[name^='m:']", objRow).each(function () {
                                var name = $(this).attr('name').replace(/.*:/, '');
                                row[name] = $(this).val();
                            });
                            row["sort"] = i - 1;
                            table.fields.push(row);
                        }
                    });
                    data.field[table.tableName] = table.fields;
                });
            },
            updateCallback: function (data) {
                if (publicMethods._filterRecord(data)) {
                    if ($(".privateSubmit")) {
                        $(".privateSubmit").attr("disabled", false).css("pointer-events", "auto");
                    }
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'}, function (index) {
                        layer.close(index);
                        window.location.href = '${ctx}/qbdms/wQbdQualityRewardsMessage/view/list';
                    });
                } else {
                    layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                }
                return false;
            }
        });

        //- 计算总金额 绑事件 开始 -------------------------------------------------------------
        $(document).on("blur", "[name='s:wQbdQualityRewardsMsgSubList:money']", computeMoney);
        $(document).on("click", ".subDeleteTr", computeMoney);

        function computeMoney() {
            if ($(this).text() == "删除") {
                $(this).parent().parent().find("[name='s:wQbdQualityRewardsMsgSubList:money']").val(0);
            }
            var objArr = $("[name='s:wQbdQualityRewardsMsgSubList:money']");
            var sumMoney = 0;
            objArr.each(function () {
                var money = $(this).val();
                if (isNaN(money * 1)) {
                    return;
                }
                sumMoney += 1 * (money == "" ? 0 : money);
            });
            $("[name='aggregateAmount']").val(Math.round(sumMoney * 100) / 100);
        }
        //- 计算总金额 绑事件 结束 -------------------------------------------------------------

    });
</script>
</body>
</html>